<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Profile extends CI_Controller {

        protected $_data;

        public function _construct(){
            $this->_data['error'] = '';
        }

	public function index()
	{
            $this->layout->view('profile/index');
	}

        public function login()
	{            
            if ($this->input->post())
                $this->loginPostAction();            
            $this->layout->view('profile/login',null,$this->_data);
	}

        /**
         * Actions when user login
         */

        protected function loginPostAction(){
            $userFlag = $this->checkLogin($this->input->post());
            if (!$userFlag){
                $this->_data['error'] = 'Неправильный email или пароль , пожалуйста попробуйте еще раз.';                
            }else{
                $this->session->set_userdata('is_logged','1');
                redirect('/dashboard/', 'refresh');
            }
        }

        /**
         * Check user email and password
         *
         * @param <type> $_data
         * @return boolean
         */
        protected function checkLogin($_data){
           ($_data['email'] == 'vedette@tut.by' && $_data['password'] == 'vincent') ? $is_user = true : $is_user = false;
           return $is_user;
        }
}
